/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import Web.shopControl;
import DA.*;
import Entity.*;
import java.sql.SQLException;
import java.util.Scanner;

/**
 *
 * @author theInterloper
 */
public class test {
    
    public static void main(String[] args) throws SQLException{  
    
        
    //<editor-fold defaultstate="collapsed" desc="menu">

        int option;
            do{     
                Scanner input = new Scanner(System.in);

                System.out.println("1.  Write test artist");
                System.out.println("2.  Write test customer");
                System.out.println("3.  Write test item");
                System.out.println("4.  Write test interested");
                System.out.println("5.  Print all artist info");
                System.out.println("6.  Print all customer info");
                System.out.println("7.  Print all item info");
                System.out.println("8.  Read / Print test interested");
                System.out.println("9.  Get itemID Max / Min");
                System.out.println("10.  Get artistID Max / Min");
                System.out.println("11.  Get customerID Max / Min");
                System.out.println("0.  Exit");
                System.out.println("Enter Option:");
                
                option = input.nextInt();


                    switch(option){
                        case 0: break;
                        case 1:
                            writeTestArtist();
                        break;
                        case 2:
                            writeTestCustomer();
                        break;
                        case 3:
                            writeTestItem();
                        break;
                        case 4:
                            writeTestInterested();
                        break;
                        case 5:
                            readTestArtist();
                        break;
                        case 6:
                            readTestCustomer();
                        break;
                        case 7:
                            readTestItem();
                        break;
                        case 8:
                            readTestInterested();
                        break;
                        case 9:
                            getItemMaxMinID("item");
                        break;
                        case 10:
                            getItemMaxMinID("artist");
                        break;
                        case 11:
                            getItemMaxMinID("customer");
                        default:
                            System.out.println("not a valid option");
                            break;
                    }
                }while(option!=0); 
        //</editor-fold>
    }
    //<editor-fold defaultstate="collapsed" desc="printers">
    private static void printCustomer(Customer customer) {
        System.out.println("ID:\t\t" + customer.getID());
        System.out.println("Username:\t" + customer.getUSERNAME());
        System.out.println("Password:\t" + customer.getPASSWORD());
        System.out.println("Firstname:\t" + customer.getFIRSTNAME());
        System.out.println("Secondname:\t" + customer.getSECONDNAME());
        System.out.println("Email:\t\t" + customer.getEMAIL());
        System.out.println("Phone:\t\t" + customer.getPHONE());
        System.out.println("Address:\t" + customer.getADDRESS1());
        System.out.println("\t\t" + customer.getADDRESS2());
        System.out.println("\t\t" + customer.getADDRESS3());
        System.out.println("");
    }

    private static void printArtist(Artist artist) {
        System.out.println("ID:\t\t" + artist.getID());
        System.out.println("Username:\t" + artist.getUSERNAME());
        System.out.println("Password:\t" + artist.getPASSWORD());
        System.out.println("Firstname:\t" + artist.getFIRSTNAME());
        System.out.println("Secondname:\t" + artist.getSECONDNAME());
        System.out.println("Email:\t\t" + artist.getEMAIL());
        System.out.println("Phone:\t\t" + artist.getPHONE());
        System.out.println("Address:\t" + artist.getADDRESS1());
        System.out.println("\t\t" + artist.getADDRESS2());
        System.out.println("\t\t" + artist.getADDRESS3());
        System.out.println("Description:\t" + artist.getDESCRIPTION());
        System.out.println("");
    }

    private static void printItem(Item item) {
        System.out.println("ID:\t\t" + item.getID());
        System.out.println("Name:\t\t" + item.getNAME());
        System.out.println("Quantity:\t" + item.getQUANTITY());
        System.out.println("Price:\t\t" + item.getPRICE());
        System.out.println("Description:\t" + item.getDESCRIPTION());
        System.out.println("Artist:\t" + item.getARTIST_ARTISTID());
        System.out.println ("");
    }
    
    private static void printInerested(Interested interested) {
        System.out.println("ID:\t\t" + interested.getID());
        System.out.println("Customer ID:\t" + interested.getCUSTOMERID());
        System.out.println("Item ID:\t" + interested.getITEMID());
        System.out.println("Artist ID:\t" + interested.getARTISTID());   
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="DB writers">
    private static void writeTestArtist() throws SQLException {
        Artist testArtist = new Artist( 999,
                                        "testUserName", 
                                        "testFirstName", 
                                        "testSecondName", 
                                        "test@Email.com", 
                                        "testPassword",
                                        "testAddress1",
                                        "testAddress2",
                                        "testAddress3",
                                        "testPhone",
                                        "testDescription");
        artistDA.write(testArtist);
    }

    private static void writeTestCustomer() throws SQLException {
        Customer customer = new Customer(999,
                                        "testUserName", 
                                        "testFirstName", 
                                        "testSecondName", 
                                        "test@Email.com", 
                                        "testPassword",
                                        "testAddress1",
                                        "testAddress2",
                                        "testAddress3",
                                        "051-396110");
        customerDA.write(customer);
    }

    private static void writeTestItem() throws SQLException {
        Item item = new Item(999,
                            "testName",
                            9,
                            99.99,
                            "testDescription",
                            99);
        itemDA.write(item);
    }

    private static void writeTestInterested() throws SQLException {
        Interested interested = new Interested(9, 99, 999, 9999);
        interestedDA.write(interested);
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="DB readers">
    private static void readTestArtist() throws SQLException {
        int[] maxMinArray = {7,7};
        maxMinArray = common.getMaxMinID("artist");
        int max = maxMinArray [0];
        int min = maxMinArray [1];
        
        for (int i = min; i < max; i++) {
            Artist artist = new Artist();
            artist = artistDA.read(i);
            printArtist(artist);  
        }
    }

    private static void readTestCustomer() throws SQLException {
        int[] maxMinArray = {7,7};
        maxMinArray = common.getMaxMinID("customer");
        int max = maxMinArray [0];
        int min = maxMinArray [1];
        
        for (int i = min; i < max; i++) {
            Customer customer = new Customer();
            customer = customerDA.read(i);
            printCustomer(customer);
        }
    }

    private static void readTestItem() throws SQLException {  
        int[] maxMinArray = {7,7};
        maxMinArray = common.getMaxMinID("item");
        int max = maxMinArray [0];
        int min = maxMinArray [1];
        
        for (int i = min; i < max; i++) {
            Item item = new Item();
            item = itemDA.read (i);
            printItem(item);
        }
    }

    private static void readTestInterested() throws SQLException {
        Interested interested = new Interested();
        interested = interestedDA.read(117);
        printInerested(interested);
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="DB various">
    private static void getItemMaxMinID(String string) throws SQLException {
        int[] maxMinArray = {7,7};
        maxMinArray = common.getMaxMinID(string);
        int max = maxMinArray [0];
        int min = maxMinArray [1];
        
        System.out.println("The first "+ string +" ID is: " + min);
        System.out.println("The last "+ string +" ID is: " + max);
        
    }
    //</editor-fold>   
}
